<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>公司收发货地址列表</title>
	<#include "/common/vue_resource.ftl">
</head>
<body>
<div id="app" v-cloak>
    <div class="app-container" @click="hideMenu">
        <div class="layui-row app-header">
            <div class="layui-col-md3">
                <button type="button" class="layui-btn layui-btn-sm" @click="add">创建公司收发货地址</button>
            </div>
            <div class="layui-col-md9 text-right">
                <input type="text" v-model="params.addressName" placeholder="公司收发货地址名称" class="layui-input">
                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary search-button" @click="seachData">查询</button>
            </div>
        </div>
        <div class="app-list">
            <div class="layui-row">
                <div class="layui-col-md9">
                    <div class="app-table-num"><span class="num">公司收发货地址列表(共 {{total}} 条)</span></div>
                </div>
                <div class="layui-col-md3 text-right">
                    <span class="prev" @click="loadPrev">上一页</span>
                    <span class="next" @click="loadNext">下一页</span>
                </div>
            </div>
            <table class="layui-table" lay-even lay-skin="nob" lay-size1="sm">
                <thead>
                <tr>
                    <th style="width:20px;">#</th>
                    <th>地址名称</th>
                    <th>默认发货地址</th>
                    <th>默认收货地址</th>
                    <th>收/发货人姓名</th>
                    <th>收/发货人电话</th>
                    <th>地址</th>
                    <th style="width:115px;">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(item, index) in rows">
                    <td>{{20 * (params.page - 1) + 1 + index}}</td>
                    <td>{{item.addressName}}</td>
                    <td>
                        <span style="margin-bottom:10px;" class="ui-accept" v-if="item.sendStatus == 1">{{item.sendStatusStr}}<br/></span>
                        <span style="margin-bottom:10px;" class="ui-no" v-if="item.sendStatus == 2">{{item.sendStatusStr}}<br/></span>
                    </td>
                    <td>
                        <span style="margin-bottom:10px;" class="ui-accept" v-if="item.receiveStatus == 1">{{item.receiveStatusStr}}<br/></span>
                        <span style="margin-bottom:10px;" class="ui-no" v-if="item.receiveStatus == 2">{{item.receiveStatusStr}}<br/></span>
                    </td>
                    <td>{{item.name}}</td>
                    <td>{{item.phone}}</td>
                    <td>{{item.province}}{{item.city}}{{item.region}}{{item.detailAddress}}</td>
                    <td class="more-parent">
                        <div class="ui-operating" @click="modify(index)">编辑</div>
                        <div class="ui-split"></div>
                        <div class="ui-operating" @click.stop="showMenu(index)">更多</div>
                        <div class="more-container" v-if="item.showMenu">
                            <div class="more-item" @click="acceptSendStatus(index)" v-if="item.sendStatus == 2">设为默认发货地址</div>
                            <div class="more-item" @click="cancelSendStatus(index)" v-if="item.sendStatus == 1">取消默认发货地址</div>
                            <div class="more-item" @click="acceptReceiveStatus(index)" v-if="item.receiveStatus == 2">设为默认收货地址</div>
                            <div class="more-item" @click="cancelReceiveStatus(index)" v-if="item.receiveStatus == 1">取消默认收货地址</div>
                            <div class="more-item" @click="remove(index)">删除</div>
                        </div>
                    </td>
                </tr>
                <tr v-if="rows.length <= 0">
                    <td colspan="8" class="text-center">没有更多数据了...</td>
                </tr>
                </tbody>
            </table>
            <div class="layui-row">
                <div class="layui-col-md6">
                    <div class="app-table-num"><span class="num">共 {{total}} 条</span></div>
                </div>
                <div class="layui-col-md6 text-right">
                    <span class="prev" @click="loadPrev">上一页</span>
                    <span class="next" @click="loadNext">下一页</span>
                </div>
            </div>
        </div>
    </div>

</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            params: {
                addressName:'',
                page: 1,
            },
            rows: [],
            total: 0,
        },
        mounted: function () {
            this.loadData();
        },
        methods: {
            seachData:function(){
                this.params.page = 1;
                this.$nextTick(function () {
                    this.loadData();
                });
            },
            loadData: function () {
                var that = this;
                $.http.post("${params.contextPath}/web/omsCompanyAddress/list.json", this.params).then(function (data) {
                    if (!data.success) {
                        $.message(data.message);
                        return;
                    }
                    that.rows = data.rows;
                    that.total = data.total;
                });
            },
            loadNext: function () {
                if (this.rows.length < 20 && this.rows.length > 0) {
                    return;
                }
                this.params.page = this.params.page + 1;
                this.loadData();
            },
            loadPrev: function () {
                if (this.params.page <= 1) {
                    return;
                }
                this.params.page = this.params.page - 1;
                this.loadData();
            },
            add:function () {
                this.showTypes = false;
                var url = "${params.contextPath!}/view/business/omsCompanyAddress/omsCompanyAddress_edit.htm";
                DialogManager.open({url:url, width:'650px', height:'100%', title:'添加公司收发货地址'});
            },
            modify: function (index) {
                var row = this.rows[index];
                var url = "${params.contextPath!}/view/business/omsCompanyAddress/omsCompanyAddress_edit.htm?id=" + row.id;
                DialogManager.open({url: url, width: '650px', height: '100%', title: '编辑公司收发货地址'});
            },
            showMenu:function (index) {
                this.hideMenu();
                this.$set(this.rows[index], "showMenu", true);
            },
            hideMenu: function () {
                var that = this;
                this.rows.forEach(function (item) {
                    that.$set(item, 'showMenu', false);
                });
            },
            remove:function (index) {//删除
                var that = this;
                $.http.post("${params.contextPath}/web/omsCompanyAddress/delete.json", {ids: this.rows[index].id}).then(function (data) {
                    $.message(data.message);
                    if (!data.success) {
                        return;
                    }
                    that.loadData();
                });
            },
            acceptSendStatus:function (index) {
                var that = this;
                $.http.post("${params.contextPath}/web/omsCompanyAddress/acceptSendStatus.json", {id: this.rows[index].id}).then(function (data) {
                    $.message(data.message);
                    if (!data.success) {
                        return;
                    }
                    that.loadData();
                });
            },
            cancelSendStatus:function (index) {
                var that = this;
                $.http.post("${params.contextPath}/web/omsCompanyAddress/cancelSendStatus.json", {id: this.rows[index].id}).then(function (data) {
                    $.message(data.message);
                    if (!data.success) {
                        return;
                    }
                    that.loadData();
                });
            },
            acceptReceiveStatus:function (index) {
                var that = this;
                $.http.post("${params.contextPath}/web/omsCompanyAddress/acceptReceiveStatus.json", {id: this.rows[index].id}).then(function (data) {
                    $.message(data.message);
                    if (!data.success) {
                        return;
                    }
                    that.loadData();
                });
            },
            cancelReceiveStatus:function (index) {
                var that = this;
                $.http.post("${params.contextPath}/web/omsCompanyAddress/cancelReceiveStatus.json", {id: this.rows[index].id}).then(function (data) {
                    $.message(data.message);
                    if (!data.success) {
                        return;
                    }
                    that.loadData();
                });
            },
        }
    });
</script>
</body>

</html>
